/* This program produces the parts of Table 1 that use household survey data 
- The table has to be assembled manually */


***** Set directories 
local dir_raw 		"~/Dropbox/Retirement gaming/raw"
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/ech_clean.dta", clear

local listcontrols = " i.t i.fsize i.ciiu2  i.year#i.fsize i.year#i.ciiu2   " 

cap drop sample_self_empl
reghdfe W age_centered if self_empl==1 [aw=weight], absorb(`listcontrols') vce(robust)
g sample_self_empl=e(sample)
reghdfe W age_centered if (empl==1 & small==1 ) [aw=weight], absorb(`listcontrols') vce(robust)
g sample_emplsmall=e(sample)
reghdfe W age_centered if (empl==1 & small==0 ) [aw=weight], absorb(`listcontrols') vce(robust)
g sample_empllarge=e(sample)

local outcomelist = "W hours " 
local controlslist1 = "bc_pe3 noempl micro micro2 larger"
local controlslist2 = "manufacturing  retailhospitality transport services "

estimates clear
*All self-empl
eststo: quietly estpost summarize `outcomelist' `controlslist1' `controlslist2' if sample_self_empl==1 [aw=weight], casewise esample
*Empl all firms
eststo: quietly estpost summarize `outcomelist' `controlslist1' `controlslist2' if sample_emplsmall==1 | sample_empllarge==1 [aw=weight], casewise esample
esttab using "`dir_output'/table1_survey.tex", replace ///
	cells("mean(fmt(2)) sd(fmt(2) par)")  nostar nonote label nonumber nodepvar ///
	mtitles("Self-Empl" "All Empl" "Empl Small"  ) ///
	style(tex) f nogaps 
** Earnings and Underreporting by employer size
estimates clear
*Empl all firms
eststo: quietly estpost summarize W  if sample_emplsmall==1 | sample_empllarge==1   [aw=weight], casewise esample
*Empl small firms
eststo: quietly estpost summarize W  if sample_emplsmall==1 [aw=weight], casewise esample
esttab using "`dir_output'/table1_survey_empl.tex", ///
	cells("mean(fmt(2)) sd(fmt(2) par)")  nostar nonote label nonumber nodepvar ///
	mtitles("All Empl" "Empl Small" ) replace ///
	style(tex) f nogaps 
estimates clear
*Empl all firms
eststo: quietly estpost summarize underrep if sample_emplsmall==1 | sample_empllarge==1   [aw=weight], casewise esample
*Empl small firms
eststo: quietly estpost summarize underrep if sample_emplsmall==1 [aw=weight], casewise esample
esttab using "`dir_output'/table1_survey_empl.tex", append ///
	cells("mean(fmt(2)) sd(fmt(2) par)")  nostar nonote label nonumber nodepvar ///
	style(tex) f nogaps nomtitles
	
exit	
